
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:jpush_flutter/jpush_flutter.dart';

import 'EcyLogger.dart';
import 'EcyUserUtil.dart';

class EcyJPushUtil {

  static Future<String> getRegistrationID() async {
    try {
      final JPush push = JPush();
      var user = await EcyUserUtil.getLoginedUserInfo2();
      if (user.uid != null && user.uid != "") {
        push.setAlias(user.uid?? "");
      }
      DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
      if (Platform.isAndroid) {
        var androidInfo = await deviceInfo.androidInfo;
        if (androidInfo.isPhysicalDevice) {
          return await push.getRegistrationID();
        }
      }
      if (Platform.isIOS) {
        var iosInfo = await deviceInfo.iosInfo;
        if (iosInfo.isPhysicalDevice) {
          return await push.getRegistrationID();
        }
      }
    } catch (e) {
      EcyLogger.log(e.toString());
    }
    return "";
  }
}